package quick.start.core.util;

import android.content.Context;
import android.util.DisplayMetrics;

public class DensityUtil {

    private static final String TAG = DensityUtil.class.getSimpleName();
    private static float dmDensityDpi = 0.0f;
    private static DisplayMetrics dm;
    private static float scale = 0.0f;
    private static DensityUtil mDensityUtil;

    private DensityUtil(Context context) {
        dm = new DisplayMetrics();
        dm = context.getApplicationContext().getResources().getDisplayMetrics();
        dmDensityDpi = dm.densityDpi;
        scale = getDmDensityDpi() / 160;
    }

    public static DensityUtil from(Context context) {
        if (null == mDensityUtil) {
            mDensityUtil = new DensityUtil(context);
        }
        return mDensityUtil;
    }
    
    public float getDmDensityDpi() {
        return dmDensityDpi;
    }

    public int dip2px(float dipValue) {
        return (int) (dipValue * scale + 0.5f);
    }
    
    public int px2dip(float pxValue) {
        return (int) (pxValue / scale + 0.5f);
    }

    @Override
    public String toString() {
        return " dmDensityDpi:" + dmDensityDpi;
    }
}
